package itdep.domain.profile;

import itdep.domain.IisEntity;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Ivan Khalopik
 * @version $Revision: 5 $ $Date: 2010-06-11 15:20:19 +0300 (Птн, 11 Июн 2010) $
 */
@Entity
@Table(name = "PROFILE")
public class Profile extends IisEntity {

	@Column(name = "FIRST_NAME", nullable = false)
	private String firstName;

	@Column(name = "LAST_NAME", nullable = false)
	private String lastName;

	@Column(name = "MIDDLE_NAME", nullable = true)
	private String middleName;

	@Column(name = "BIRTH_DATE", nullable = true)
	private Date birthDate;

	@Type(type = "ga.hibernate.OrderedEnumUserType", parameters = {@Parameter(name = "enumClass", value = "itdep.domain.profile.Sex")})
	@Column(name = "SEX", nullable = false)
	private Sex sex = Sex.UNKNOWN;

	@Type(type = "ga.hibernate.OrderedEnumUserType", parameters = {@Parameter(name = "enumClass", value = "itdep.domain.profile.MaritalStatus")})
	@Column(name = "MARITAL_STATUS", nullable = false)
	private MaritalStatus maritalStatus = MaritalStatus.UNKNOWN;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ID_NATIONALITY", nullable = true)
	private Nationality nationality;

	@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@PrimaryKeyJoinColumn
	private IdentityCard identityCard = new IdentityCard();

	@Type(type = "ga.hibernate.OrderedEnumUserType", parameters = {@Parameter(name = "enumClass", value = "itdep.domain.profile.Education")})
	@Column(name = "EDUCATION", nullable = false)
	private Education education = Education.UNKNOWN;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "ID_EDUCATION_INSTITUTION", nullable = true)
	private Organization educationInstitution;

	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinColumn(name = "ID_PHOTO", nullable = true)
	private Picture photo;

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "PROFILE_CONTACT",
			joinColumns = @JoinColumn(name = "ID_PROFILE", nullable = false),
			inverseJoinColumns = @JoinColumn(name = "ID_CONTACT", nullable = false))
	private Set<Contact> contacts = new HashSet<Contact>();

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "PROFILE_ADDRESS",
			joinColumns = @JoinColumn(name = "ID_PROFILE", nullable = false),
			inverseJoinColumns = @JoinColumn(name = "ID_ADDRESS", nullable = false))
	private Set<Address> addresses = new HashSet<Address>();


	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getMiddleName() {
		return middleName;
	}

	public void setMiddleName(String middleName) {
		this.middleName = middleName;
	}

	public Date getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}

	public MaritalStatus getMaritalStatus() {
		return maritalStatus;
	}

	public void setMaritalStatus(MaritalStatus maritalStatus) {
		this.maritalStatus = maritalStatus;
	}

	public Nationality getNationality() {
		return nationality;
	}

	public void setNationality(Nationality nationality) {
		this.nationality = nationality;
	}

	public IdentityCard getIdentityCard() {
		return identityCard;
	}

	public void setIdentityCard(IdentityCard identityCard) {
		this.identityCard = identityCard;
	}

	public Sex getSex() {
		return sex;
	}

	public void setSex(Sex sex) {
		this.sex = sex;
	}

	public Education getEducation() {
		return education;
	}

	public void setEducation(Education education) {
		this.education = education;
	}

	public Organization getEducationInstitution() {
		return educationInstitution;
	}

	public void setEducationInstitution(Organization educationInstitution) {
		this.educationInstitution = educationInstitution;
	}

	public Set<Contact> getContacts() {
		return contacts;
	}

	public void setContacts(Set<Contact> contacts) {
		this.contacts = contacts;
	}

	public Set<Address> getAddresses() {
		return addresses;
	}

	public void setAddresses(Set<Address> addresses) {
		this.addresses = addresses;
	}

	public Picture getPhoto() {
		return photo;
	}

	public void setPhoto(Picture photo) {
		this.photo = photo;
	}
}